package org.zjx.log;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * AsynchronousLogHandler异步地处理日志，使用单线程池。
 */
public class AsynchronousLogHandler implements LogHandler {
    private ExecutorService executorService;
    private LogHandler logHandler;

    public AsynchronousLogHandler(LogHandler logHandler) {
        this.executorService = Executors.newSingleThreadExecutor();
        this.logHandler = logHandler;
    }

    @Override
    public void handleLog(LogLevel level, String message) {
        executorService.submit(() -> logHandler.handleLog(level, message));
    }

    public void shutdown() {
        executorService.shutdown();
    }
}

